<?php
namespace app\common\model;
use think\Model;

class Order extends Model
{
    protected $connection = 'db_config_aiqi';
    public function getrechargedata($map){
        $data = $this->where($map)->order("pay_time desc")->select()->toArray();
        return $data;
    }

    public function creatOrder($data){
        $order = self::setOrder($data);
       return self::insertGetId($order);
    }

    private static function setOrder($data){
        $order = [
            'uid'=>$data['uid'] ?? "0",
            'cid'=>$data['cid'] ?? "0",
            'gid'=>$data['gid'] ?? "0",
            'sid'=>$data['sid'] ?? "0",
            'goods_name'=>$data['goods_name'] ?? "订单充值",
            'num'=>$data['num'] ?? "1",
            'order_no'=>$data['order_no'] ?? "",
            'trade_no'=>$data['trade_no'] ?? "",
            'amount'=>round($data['amount']/100,2) ?? "0",
            'order_status'=>$data['order_status'] ?? "0",
            'type'=>$data['type'] ?? "1",
            'note'=>$data['note'] ?? '',
//            'pay_time'=>date('Y-m-d H:i:s', time()),
            'creat_time'=>date('Y-m-d H:i:s'),
            'update_time'=>date('Y-m-d H:i:s'),
            'is_test'=>$data['is_test'] ?? "0",
        ];


        return $order;
    }

    public static function getOrder($order_no)
    {
        return self::where(['order_no'=>$order_no])->find();
    }


    public static function getOrderList($field, $where)
    {
        return self::field($field)->where($where)->select();
    }
}